package net.sh.dpinfrastructure.support.spring.configuration;

import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.type.AnnotatedTypeMetadata;

import net.sh.dpinfrastructure.config.DPConfig;
import net.sh.dpinfrastructure.config.DPFileConfig;

/**
 * 
 * 配置工具的配置类
 * 
 * @version 1.0
 * @since JDK1.7
 * @author shaohui
 * @company 上海朝阳永续信息技术有限公司
 * @copyright (c) 2016 SunTime Co'Ltd Inc. All rights reserved.
 * @date 2016年8月8日 下午2:05:43
 */
@Configuration
@Conditional(DPConfigCondition.class)
public class DPConfigConfiguration {
    
    private Logger LOGGER = LoggerFactory.getLogger(DPConfigConfiguration.class);
    
    @Bean
    public DPConfig getDPConfig() {
        String configFilePath = System.getProperty("config.path");
        if (StringUtils.isNotEmpty(configFilePath)) {
            return new DPFileConfig(configFilePath);
        }
        Properties property = new Properties();
        try {
            property.load(this.getClass().getClassLoader().getResourceAsStream("dataplatform.conf"));
        } catch (Exception e) {
            LOGGER.warn("no property file assigned");
        }
        return new DPFileConfig(property);
    }
    
}
